package view.skill
{
import core.Language;

import framework.core.TipManager;
import framework.proxy.ComponentProxy;
import framework.view.components.button.ButtonProxy;
import framework.view.components.container.IRenderProxy;
import framework.view.components.container.RepeaterProxy;

import values.avatar.IAvatarValue;
import values.skill.SkillValue;

import view.component.asset.IconProxy;
import view.hero.HeroSkillInfoProxy;

/**
 * SkillDetailUIProxy
 * @author jliang
 *
 */
public class SkillDetailUIProxy extends ComponentProxy
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function SkillDetailUIProxy()
	{
		super();
	}
	
	//==========================================================================
	//  Properties
	//==========================================================================
	public function get icon():IconProxy
	{
		return proxys["icon"];
	}
	
	public function get skill():HeroSkillInfoProxy
	{
		return proxys["skill"];
	}
	
	public function get info():SkillInfoUIProxy
	{
		return proxys["info"];
	}
	
	public function get list():RepeaterProxy
	{
		return proxys["list"];
	}
	
	public function get replaceBtn():ButtonProxy
	{
		return proxys["replaceBtn"];
	}
	
	public function get upgradeBtn():ButtonProxy
	{
		return proxys["upgradeBtn"];
	}
	
	protected var vo:IAvatarValue;
	
	public function set data(value:*):void
	{
		vo = value;
		
		info.avatar = vo;
		
		icon.load(vo.template.getAssetByKey("icon").url);
		
		skill.data = vo;
		
		var skills:Vector.<SkillValue> = new Vector.<SkillValue>();
		for (var i:int = 0; i < vo.template.skill.normalSkills.length; i++)
		{
			skills.push(vo.getSkillBySlot(i));
		}
		skills.push(vo.ultimateSkill);
		
		list.data = skills;
		
		list.selectedIndex = vo.selectedSkill.slot;
	}
	
	public function get data():*
	{
		return vo;
	}
	
	protected function get currentSkill():SkillValue
	{
		return info.data;
	}
	//==========================================================================
	//  Overridden methods: RepeaterRenderProxy
	//==========================================================================	
	override protected function get proxyMapping():Array
	{
		return [ 
			{ skin:"replaceBtn", classRef: ButtonProxy, id:"replaceBtn", onClick: clickToReplaceSkillHandler, onMouseOver:mouseOverReplaceButtonHandler },
			{ skin:"upgradeBtn", classRef: ButtonProxy, id:"upgradeBtn", onClick: clickToUpgradeSkillHandler, onMouseOver:mouseOverUpgradeButtonHandler },
			{ skin:"icon", classRef: IconProxy, id:"icon" },
			{ skin:"list", classRef: RepeaterProxy, id:"list", renderProxyRef:SkillItemRenderProxy, onItemSelected:skillSelectedHandler },
			{ skin:"info", classRef: SkillInfoUIProxy, id:"info" },
			{ skin:"skill", classRef: HeroSkillInfoProxy, id:"skill" }
		];
	}
	//==========================================================================
	//  Public methods
	//==========================================================================
	
	//==========================================================================
	//  Event handlers
	//==========================================================================
	protected function skillSelectedHandler(render:IRenderProxy):void
	{
		info.data = render.data;
		
		replaceBtn.enabled = replaceBtn.visible = (vo.ultimateSkill.key != currentSkill.key);		
		replaceBtn.enabled = (vo.selectedSkill.key != currentSkill.key && currentSkill.isUnLocked);
	}
	
	protected function clickToReplaceSkillHandler():void
	{
		vo.changeSkill(currentSkill.key);
		
		replaceBtn.enabled = (vo.selectedSkill.key != currentSkill.key && currentSkill.isUnLocked);	
	}
	
	protected function clickToUpgradeSkillHandler():void
	{
		
	}
	
	protected function mouseOverReplaceButtonHandler():void
	{
		TipManager.showTip(replaceBtn.skinContent, Language.getText("@replace_skill_button_tip"));
	}
	
	protected function mouseOverUpgradeButtonHandler():void
	{
		TipManager.showTip(upgradeBtn.skinContent, Language.getText("@upgrade_skill_button_tip"));
	}
}
}




